
package kaizone.haining.chaobohui.args;

import java.util.Calendar;
import java.util.HashMap;

import android.text.TextUtils;

import kaizone.haining.chaobohui.util.Lunar;
import kaizone.haining.chaobohui.util.Utils;

public class GuanChaoTimeable {

    public String[] Ri15or15 = {
            "11:45", "23:40", "11:30", "23:20", "11:35", "23:25", "11:10", "23:05"
    };

    public String[] Ri16or01 = {
            "12:15", "0:10", "11:50", "23:45", "12:05", "0:00", "11:45", "23:35"
    };

    public String[] Ri17or02 = {
            "12:48", "0:43", "12:25", "0:10", "12:45", "0:35", "12:15", "0:05"
    };

    public String[] Ri18or03 = {
            "13:25", "1:16", "13:15", "1:05", "13:23", "1:15", "13:05", "1:00"
    };

    public String[] Ri19or04 = {
            "14:05", "1:50", "13:45", "1:40", "14:00", "1:50", "13:40", "1:30"
    };

    public String[] Ri20or05 = {
            "14:40", "2:25", "14:26", "2:15", "14:35", "2:20", "14:15", "2:10"
    };

    public String[] Ri21or06 = {
            "15:20", "3:05", "15:05", "2:55", "15:15", "3:00", "15:00", "2:55"
    };

    public String[] Ri22or07 = {
            "16:00", "3:45", "15:45", "3:35", "16:00", "3:45", "15:45", "3:40"
    };

    public String[] Ri23or08 = {
            "16:40", "4:25", "16:25", "4:15", "16:45", "4:30", "16:30", "4:25"
    };

    public String[] Ri24or09 = {
            "17:20", "5:05", "17:05", "5:00", "17:30", "5:15", "17:15", "5:05"
    };

    public String HZ_01 = "初一";

    public String HZ_02 = "初二";

    public String HZ_03 = "初三";

    public String HZ_04 = "初四";

    public String HZ_05 = "初五";

    public String HZ_06 = "初六";

    public String HZ_07 = "初七";

    public String HZ_08 = "初八";

    public String HZ_09 = "初九";

    public String HZ_15 = "十五";

    public String HZ_16 = "十六";

    public String HZ_17 = "十七";

    public String HZ_18 = "十八";

    public String HZ_19 = "十九";

    public String HZ_20 = "廿";

    public String HZ_21 = "廿一";

    public String HZ_22 = "廿二";

    public String HZ_23 = "廿三";

    public String HZ_24 = "廿四";

    public int SPRING = 0;

    public int SUMMER = 1;

    public int AUTUMN = 2;

    public int WINTER = 3;

    private HashMap<String, String[]> mGCTimeTable;

    private HashMap<String, Integer> mJQTable;

    public GuanChaoTimeable() {
        mGCTimeTable = new HashMap<String, String[]>();
        mGCTimeTable.put(HZ_01, Ri16or01);
        mGCTimeTable.put(HZ_02, Ri17or02);
        mGCTimeTable.put(HZ_03, Ri18or03);
        mGCTimeTable.put(HZ_04, Ri19or04);
        mGCTimeTable.put(HZ_05, Ri20or05);
        mGCTimeTable.put(HZ_06, Ri21or06);
        mGCTimeTable.put(HZ_07, Ri22or07);
        mGCTimeTable.put(HZ_08, Ri23or08);
        mGCTimeTable.put(HZ_09, Ri24or09);
        mGCTimeTable.put(HZ_15, Ri15or15);
        mGCTimeTable.put(HZ_16, Ri16or01);
        mGCTimeTable.put(HZ_17, Ri17or02);
        mGCTimeTable.put(HZ_18, Ri18or03);
        mGCTimeTable.put(HZ_19, Ri19or04);
        mGCTimeTable.put(HZ_20, Ri20or05);
        mGCTimeTable.put(HZ_21, Ri21or06);
        mGCTimeTable.put(HZ_22, Ri22or07);
        mGCTimeTable.put(HZ_23, Ri23or08);
        mGCTimeTable.put(HZ_24, Ri24or09);

        mJQTable = new HashMap<String, Integer>();
        mJQTable.put("二月", SPRING);
        mJQTable.put("三月", SPRING);
        mJQTable.put("四月", SPRING);
        mJQTable.put("五月", SUMMER);
        mJQTable.put("六月", SUMMER);
        mJQTable.put("七月", SUMMER);
        mJQTable.put("八月", AUTUMN);
        mJQTable.put("九月", AUTUMN);
        mJQTable.put("十月", AUTUMN);
        mJQTable.put("十一月", WINTER);
        mJQTable.put("十二月", WINTER);
        mJQTable.put("一月", WINTER);
    }

    public String[] getGCTime(Lunar lunar) {
        String[] time = new String[2];
        String mm = lunar.getHZMM();
        int jq = mJQTable.get(mm);
        int pos = jq * 2;

        String dd = lunar.getHZDD();
        String[] timetable = mGCTimeTable.get(dd);

        if (timetable == null || timetable.length < 2)
            return null;

        time[0] = timetable[pos];
        time[1] = timetable[pos + 1];

        return time;

    }

    public String getChaoTime(Lunar lunar) {
        String[] time = getGCTime(lunar);
        if (time == null || time.length < 1)
            return null;
        return time[0];
    }

    public String getChaoXunText() {
        StringBuilder sb = new StringBuilder();
        try {
            String riqi = Utils.dateHZ();
            sb.append(riqi).append("\t\t");

            Calendar today = Calendar.getInstance();
            // today.setTime(Lunar.chineseDateFormat.parse("2013年08月31日"));
            today.setTime(Lunar.chineseDateFormat.parse(riqi));
            Lunar lunar = new Lunar(today);
            sb.append(lunar.getHZMMDD2()).append("\n");

            String[] gctime = getGCTime(lunar);

            if (gctime == null || gctime.length < 2 || TextUtils.isEmpty(gctime[0])
                    || TextUtils.isEmpty(gctime[1])) {
                sb.append("今日无潮").append("\n\n");
            } else {
                sb.append("今日海宁观潮时间").append("\n");
                sb.append("潮：").append(gctime[0]).append("\t\t").append("汐：").append(gctime[1]);
                sb.append("\n\n");
            }

            sb.append("注:由于受气候的影响,请提前40分钟候潮!潮汛咨询电话:0573--87617100");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sb.toString();

    }

}
